#include "gammapinode.h"
#include <qmath.h>

GammaPiNode::GammaPiNode(double val):
        Node(val)
{
    alphaNode = -1;
    betaNode  = -1;    
}

GammaPiNode::GammaPiNode(QString lbl, double val, double sd, Node * alphaNode, Node * betaNode, bool observed):
        Node(lbl, val, sd, observed)
{
    setAlphaNode(alphaNode);
    setBetaNode(betaNode);    
}


bool GammaPiNode::inRange(double v)
{
    return 0.0 < v;
}

void GammaPiNode::setAlphaNode(Node * node)
{
    alphaNode = addParentNode(node);
}

void GammaPiNode::setBetaNode(Node * node)
{
    betaNode = addParentNode(node);
}

double GammaPiNode::computeLogLikelihood()
{
    double pVal = parents->at(alphaNode)->getValue();
    double a = pow(pVal,
                   M_PI);

    double b = parents->at(betaNode)->getValue();

    double val = this->getValue();

    double p = gsl_ran_gamma_pdf(val,
                                 a,
                                 b);

    return VALID_LOG(p);
}
